﻿using PRO.DbProvider;
using PRO.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PRO.ORM;
using System.Data;

namespace PRO.Data.SqlServer
{
    public partial class DataProvider : IDataProvider
    {
        public bool AddDeliver_Address(Deliver_address_Info info)
        {
            if (info.Insert() > 0)
                return true;
            else
                return false;
        }
        public DataTable GetMyDeliver_Address(int userid)
        {
            SqlHelper helper = new SqlSelect("Pro_Deliver_address");
            helper.AddFeild("id", "userid", "consignee", "address", "zip", "moble", "phone", "default_addr");
            helper.AddWhereAnd("userid", userid, SqlDbType.Int, 4, "=");
            helper.TopCounts = 20;
            return (DataTable)helper.Run();
        }
        public DataTable GetDeliver_Address(int id, int userid)
        {
            SqlHelper helper = new SqlSelect("Pro_Deliver_address");
            helper.AddFeild("id", "userid", "consignee", "address", "zip", "moble", "phone", "default_addr");
            helper.AddWhereAnd("userid", userid, SqlDbType.Int, 4, "=");
            helper.AddWhereAnd("id", id, SqlDbType.Int, 4, "=");
            return (DataTable)helper.Run();
        }
        public bool SetDefault(int id, int userid)
        {
            string sql = "update Pro_Deliver_address set default_addr=1 where userid=" + userid + " and id=" + id + " and default_addr=0";
            return Convert.ToBoolean(DbHelper.ExecuteNonQuery(CommandType.Text, sql));
        }
        public bool DelDeliver_Address(int id, int userid)
        {
            string sql = "delete Pro_Deliver_address where userid=" + userid + " and id=" + id;
            return Convert.ToBoolean(DbHelper.ExecuteNonQuery(CommandType.Text, sql));
        }
    }
}
